(() => {
  if (!window.hasOwnProperty("ClipboardJS")) {
    let script = document.createElement("script");
    script.src =
      "https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.11/clipboard.min.js";
    document.head.appendChild(script);
  }
  if (!location.href.includes("/zentao/my-dynamic")) {
    alert(
      "%E8%AF%B7%E5%85%88%E7%99%BB%E5%BD%95%E7%A6%85%E9%81%93%E5%B9%B6%E8%BF%9B%E5%85%A5%E6%88%91%E7%9A%84%E5%9C%B0%E7%9B%98>%E5%8A%A8%E6%80%81"
    );
    return;
  }
  let nums = Number(
    prompt(
      "%E8%AF%B7%E8%BE%93%E5%85%A5%E8%A6%81%E6%8F%90%E5%8F%96%E7%9A%84%E7%BC%96%E5%8F%B7%E6%95%B0%E9%87%8F:"
    )
  );
  setTimeout(() => {
    let str = "fix bug ";
    let nodes = document.querySelectorAll("span.label-id");
    nodes = nodes ? nodes : [];
    let nodeLen = nodes.length;
    if (isNaN(nums)) {
      nums = nodeLen;
    }
    if (!nodes.length) {
      alert(
        "%E5%BD%93%E5%89%8D%E9%A1%B5%E9%9D%A2%E6%97%A0bug%E7%BC%96%E5%8F%B7"
      );
      return;
    }
    if (nums > nodeLen) {
      nums = nodeLen;
    }
    let start = nodeLen - nums - 1;
    for (let index = nodeLen - 1; index > start; index--) {
      str += nodes[index].innerText + " ";
    }
    let btn = document.createElement("button");
    let btnClose = document.createElement("button");
    btnClose.innerText = "关闭";
    btnClose.style = "margin-right:20px;";
    btn.innerText = "点击复制";
    btn.className = "clipboard-btn";
    btn.setAttribute("data-clipboard-text", str);
    new ClipboardJS(".clipboard-btn");
    let container = document.createElement("div");
    container.style =
      "width:100%;height:100%;position:absolute;top:0;z-index:999999;";
    let div = document.createElement("div");
    let div2 = document.createElement("div");
    div2.style = "text-align:right";
    div.style =
      "top:30%;left:50%;position:absolute;transform:translate(0,-50%);background:white;padding:20px";
    div.innerHTML = `%E7%94%9F%E6%88%90%E7%BB%93%E6%9E%9C(${nums}/${nodeLen}%E6%9D%A1):<br/><br/><br/><br/><br/>${str}<br/><br/><br/><br/>ps:%E5%BD%93%E5%89%8D%E9%A1%B5%E9%9D%A2%E6%9C%80%E5%A4%9A${nodeLen}%E6%9D%A1%E8%AE%B0%E5%BD%95,%E9%BB%98%E8%AE%A4%E6%8C%89%E6%9C%80%E5%A4%A7%E6%9D%A1%E6%95%B0%E7%94%9F%E6%88%90<br/><br/>`;
    div2.appendChild(btnClose);
    div2.appendChild(btn);
    div.appendChild(div2);
    container.appendChild(div);
    document.querySelector('html').scrollTop=0;
    document.body.appendChild(container);
    btnClose.onclick = () => {
      document.body.removeChild(container);
    };
    btn.onclick = () => {
      setTimeout(() => {
        document.body.removeChild(container);
      }, 1);
    };
  }, 120);
})();